package com.swc.factory;



import com.swc.constant.HeaderConstant;
import com.swc.secret.AbstractSecret;
import com.swc.secret.AesSecret;
import com.swc.secret.DesRsaSecret;
import com.swc.secret.DesSecret;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 加解密模式工厂
 * @author huyupeng
 * @date 2020/9/18 8:53
 */
public class EncryptModeFactory {

    private static ConcurrentMap<String, AbstractSecret> map = new ConcurrentHashMap<>(3);

    static {
        map.put(HeaderConstant.HEADER_ENCRYPT_MODE_DES_RSA, new DesRsaSecret());
        map.put(HeaderConstant.HEADER_ENCRYPT_MODE_DES, new DesSecret());
        map.put(HeaderConstant.HEADER_ENCRYPT_MODE_AES, new AesSecret());
    }

    public AbstractSecret getEncryptMode(String mode) {
        AbstractSecret secret = map.get(mode);
        if (secret == null) {
            throw new RuntimeException("暂不支持该加密模式");
        }
        return secret;
    }

}
